{include file="public/layout" /}
<style type="text/css">
    .ncap-form-default dt.tit em.none{
        display: none;
    }
</style>
<body class="bodystyle" style="cursor: default; -moz-user-select: inherit; min-width:400px;">
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page min-hg-c-10" style="min-width: 400px;">
    <div class="flexigrid">
        <form class="form-horizontal" id="postAlipayForm" onselectstart="return false;">
            <input type="hidden" name="pay_id" value="{$Config.pay_id}">
            <div class="ncap-form-default"/>
                <dl class="row">
                    <dt class="tit">
                        <label>支付功能</label>
                    </dt>
                    <dd class="opt">
                        <label class="curpoin"><input id="is_open_alipay0" name="pay_info[is_open_alipay]" value="0" type="radio" {if condition="!isset($pay_info.is_open_alipay) || empty($pay_info.is_open_alipay)"} checked="checked"{/if}>开启</label>
                        &nbsp;
                        <label class="curpoin"><input id="is_open_alipay1" name="pay_info[is_open_alipay]" value="1" type="radio" {if condition="isset($pay_info.is_open_alipay) && $pay_info.is_open_alipay == 1"} checked="checked"{/if}>关闭</label>
                    </dd>
                </dl>
                <dl class="row">
                    <dt class="tit">
                        <label for="uname"><em></em>使用支付宝版本</label>
                    </dt>
                    <dd class="opt">
                        <label>
                            <input type="radio" name="pay_info[version]" onclick="switch_set(this);" value="0" {if condition="empty($php_version) && empty($pay_info.version)"}checked="checked"{/if} />新版接口
                            <span style="padding-left: 10px; color: #C0C0C0;">支持<font color="red">php5.5.0</font>或更高版本！(阿里云空间必须php7.0或以上)</span>
                        </label>
                        <br/>
                        <label>
                            <input type="radio" name="pay_info[version]" onclick="switch_set(this);" value="1" {if condition="$pay_info.version == 1 || $php_version == 1"}checked="checked"{/if} />旧版接口
                            <span style="padding-left: 10px; color: #C0C0C0;">可支持<font color="red">php5.4</font>或更高版本！</span>
                        </label>
                    </dd>
                </dl>

                <div id="new_version" {if condition="$pay_info.version == 1 || $php_version == 1"}class="none"{/if}>
                    <dl class="row">
                        <dt class="tit">
                            <label><em class="em_empty {notempty name='$pay_info.is_open_alipay'} none {/notempty}">*</em>支付终端</label>
                        </dt>
                        <dd class="opt">
                            <ul class="nc-row ncap-waybill-list">
                                <li style="width: 100%;">
                                    <label class="label">
                                        <input class="check" type="checkbox" name="pay_terminal[computer]" value="1" {if condition="!empty($Config.pay_terminal.computer)"} checked="checked" {/if} onclick="ConfigDetect(this);">电脑端
                                        <input type="hidden" name="pay_terminal[c_mark]" id="computer_mark" value="{$Config.pay_terminal.c_mark}">
                                    </label>
                                    &nbsp; &nbsp;
                                    <label class="label">
                                        <input class="check" type="checkbox" name="pay_terminal[mobile]" value="2" {if condition="!empty($Config.pay_terminal.mobile)"} checked="checked" {/if} onclick="ConfigDetect(this);">移动端
                                        <input type="hidden" name="pay_terminal[m_mark]" id="mobile_mark" value="{$Config.pay_terminal.m_mark}">
                                    </label>
                                    <a href="JavaScript:void(0);" onclick="click_to_eyou_1575506523('https://www.eyoucms.com/plus/view.php?aid=11848&origin_eycms=1', '终端签约教程');" style="font-size: 12px; padding-left: 10px; position: absolute;">[终端签约教程]</a>
                                    <!-- <a href="JavaScript:void(0);" onclick="click_to_eyou_1575506523('https://www.eyoucms.com/plus/view.php?aid=11848&origin_eycms=1', '终端签约教程');" id="UseTutorial" {if condition="in_array(2, $Config.pay_terminal)"} style="font-size: 12px; padding-left: 10px; position: absolute;" {else/} style="font-size: 12px; padding-left: 10px; position: absolute; display: none;" {/if}>[使用教程]</a> -->
                                </li>
                            </ul>
                        </dd>
                    </dl>
                    <dl class="row">
                        <dt class="tit">
                            <label for="username"><em class="em_empty {notempty name='$pay_info.is_open_alipay'} none {/notempty}">*</em>支付宝APPID</label>
                        </dt>
                        <dd class="opt">
                            <input type="text" name="pay_info[app_id]" id="app_id" value="{$pay_info.app_id|default=''}" class="input-txt" autocomplete="off">
                            <p class="notic">请输入您的支付宝APPID，用于支付宝支付。</p>
                        </dd>
                    </dl>
                    <dl class="row">
                        <dt class="tit">
                            <label for="username"><em class="em_empty {notempty name='$pay_info.is_open_alipay'} none {/notempty}">*</em>商户私钥</label>
                        </dt>
                        <dd class="opt">
                            <textarea rows="5" cols="80" id="merchant_private_key" name="pay_info[merchant_private_key]" style="height:120px;" autocomplete="off">{$pay_info.merchant_private_key|default=''}</textarea>
                            <p class="notic">请输入您的商户私钥，用于支付宝支付。</p>
                        </dd>
                    </dl>
                    <dl class="row">
                        <dt class="tit">
                            <label for="username"><em class="em_empty {notempty name='$pay_info.is_open_alipay'} none {/notempty}">*</em>支付宝公钥</label>
                        </dt>
                        <dd class="opt">
                            <textarea rows="5" cols="80" id="alipay_public_key" name="pay_info[alipay_public_key]" style="height:106px;" autocomplete="off">{$pay_info.alipay_public_key|default=''}</textarea>
                            <p class="notic">请输入您的支付宝公钥，用于支付宝支付。</p>
                        </dd>
                    </dl>
                </div>

                <div id="old_version" {if condition="empty($php_version) && empty($pay_info.version)"}class="none"{/if}>
                    <dl class="row">
                        <dt class="tit">
                            <label for="username"><em class="em_empty {notempty name='$pay_info.is_open_alipay'} none {/notempty}">*</em>支付宝账号</label>
                        </dt>
                        <dd class="opt">
                            <input type="text" name="pay_info[account]" id="account" value="{$pay_info.account|default=''}" class="input-txt" autocomplete="off">
                            <p class="notic">请输入您的支付宝账号，用于支付宝支付。</p>
                        </dd>
                    </dl>
                    <dl class="row">
                        <dt class="tit">
                            <label for="username"><em class="em_empty {notempty name='$pay_info.is_open_alipay'} none {/notempty}">*</em>交易安全校验码</label>
                        </dt>
                        <dd class="opt">
                            <input type="text" name="pay_info[code]" id="code" value="{$pay_info.code|default=''}" class="input-txt" autocomplete="off">
                            <p class="notic">请输入您的交易安全校验码，用于支付宝支付。</p>
                        </dd>
                    </dl>
                    <dl class="row">
                        <dt class="tit">
                            <label for="username"><em class="em_empty {notempty name='$pay_info.is_open_alipay'} none {/notempty}">*</em>合作者身份ID</label>
                        </dt>
                        <dd class="opt">
                            <input type="text" name="pay_info[id]" id="id" value="{$pay_info.id|default=''}" class="input-txt" autocomplete="off">
                            <p class="notic">请输入您的合作者身份ID，用于支付宝支付。</p>
                        </dd>
                    </dl>
                </div>
                <dl class="row">
                    <div class="bot" style="padding-bottom: 0px;">
                        <a href="JavaScript:void(0);" onclick="alipayset();" class="ncap-btn-big ncap-btn-green" id="submitAlipayBtn">确认提交</a>
                        &nbsp;<a href="JavaScript:void(0);" onclick="click_to_eyou_1575506523('https://www.eyoucms.com/plus/view.php?aid=11284&origin_eycms=1','支付宝支付配置教程')" style="font-size: 12px;padding-left: 10px;position:absolute;top: 30px">不会配置？</a>
                    </div>
                </dl>
            </div>
        </form>
    </div>
</div>

<script type="text/javascript">
    var parentObj = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引

    $(function(){
        $("input[name='pay_info[is_open_alipay]']").click(function(){
            if(1 == $(this).val()){
                $('.em_empty').hide();
            } else {
                $('.em_empty').show();
            }
        });
    });

    function php_version(is){
        var php_version = {$php_version};
        // php_version=1，表示php本版低于5.5.0，不可用新版支付方式
        if (php_version == 1) {
            if (is == true) {
                layer.alert('PHP版本低于5.5.0，不可用新版支付方式，请使用旧版！', {icon: 2, title:false});
            }
            $("#postAlipayForm input[name='pay_info[version]'][value=1]").attr("checked","checked");
            return false;
        }
        return true;
    }

    function switch_set(obj){
        var switch_set = $(obj).val();
        if (switch_set == 0) {
            if (php_version(true)) {
                $("#postAlipayForm #new_version").show();
                $("#postAlipayForm #old_version").hide();
            }
        }else if (switch_set == 1) {
            $("#postAlipayForm #new_version").hide();
            $("#postAlipayForm #old_version").show();
        }
    }

    function alipayset(){
        var is_open_alipay = $("#postAlipayForm input[name='pay_info[is_open_alipay]']:checked").val();
        if (is_open_alipay == 0){
            var switch_set = $("#postAlipayForm input[name='pay_info[version]']:checked").val();
            if (switch_set == 0) {
                // 新版判断
                if($('#postAlipayForm input[name="pay_terminal[computer]"]:checked').val() != 1 && $('#postAlipayForm input[name="pay_terminal[mobile]"]:checked').val() != 1){
                    layer.alert('至少勾选一个支付终端！', {icon: 2, title:false});
                    return false;
                }
                if($('#postAlipayForm #app_id').val() == ''){
                    layer.alert('支付APPID不能为空！', {icon: 2, title:false});
                    return false;
                }

                if($('#postAlipayForm #merchant_private_key').val() == ''){
                    layer.alert('商户私钥不能为空！', {icon: 2, title:false});
                    return false;
                }

                if($('#postAlipayForm #alipay_public_key').val() == ''){
                    layer.alert('支付宝公钥不能为空！', {icon: 2, title:false});
                    return false;
                }
            }else if (switch_set == 1) {
                // 旧版判断
                if($('#postAlipayForm #account').val() == ''){
                    layer.alert('支付宝账号不能为空！', {icon: 2, title:false});
                    return false;
                }

                if($('#postAlipayForm #code').val() == ''){
                    layer.alert('交易安全校验码不能为空！', {icon: 2, title:false});
                    return false;
                }

                if($('#postAlipayForm #id').val() == ''){
                    layer.alert('合作者身份ID不能为空！', {icon: 2, title:false});
                    return false;
                }
            }
        }

        layer_loading('正在处理');
        $.ajax({
            url: "{:url('PayApi/save_pay_api_config', ['_ajax'=>1])}",
            type: 'POST',
            dataType: 'JSON',
            data: $('#postAlipayForm').serialize(),
            success: function(res){
                layer.closeAll();
                if (1 == res.code) {
                    var _parent = parent;
                    _parent.layer.close(parentObj);
                    _parent.layer.msg(res.msg, {shade: layer_shade, time: 1000});
                } else {
                    showErrorAlert(res.msg);
                }
            },
            error: function(e){
                layer.closeAll();
                showErrorAlert(e.responseText);
                return false;
            }
        });
    }

    // 记录支付宝支付配置支付终端是否已签约
    function ConfigDetect(obj) {
        if ($(obj).prop('checked')) {
            // 检测是否完善支付宝配置
            var AppID = $('#app_id').val();
            var MerchantPrivateKey = $('#merchant_private_key').val();
            var AlipayPublicKey = $('#alipay_public_key').val();
            if (!AppID || !MerchantPrivateKey || !AlipayPublicKey) {
                $(obj).attr('checked', false);
                layer.alert('请先完善支付宝配置再选择', {icon: 2, title: false});
                return false;
            }

            // 是否签约
            if (1 == $(obj).val()) {
                var computerMark = $('#computer_mark').val();
                if (1 != computerMark) {
                    var msg = '<span style="color: red;">【电脑网站支付】</span>';
                    layer.confirm('是否已在支付宝应用能力列表中签约'+msg+'能力？', {
                        shade: layer_shade,
                        area: ['480px', '190px'],
                        move: false,
                        title: '提示',
                        btnAlign:'r',
                        closeBtn: 3,
                        btn: ['已签约，不再提醒', '未签约'],
                        success: function () {
                              $(".layui-layer-content").css('text-align', 'left');
                          }
                    }, function() {
                        $('#computer_mark').val(1);
                        layer.closeAll();
                    }, function(index) {
                        $(obj).attr('checked', false);
                        layer.closeAll(index);
                    });
                }
            } else {
                var mobileMark = $('#mobile_mark').val();
                if (2 != mobileMark) {
                    var msg = '<span style="color: red;">【手机网站支付】</span>';
                    layer.confirm('是否已在支付宝应用能力列表中签约'+msg+'能力？', {
                        shade: layer_shade,
                        area: ['480px', '190px'],
                        move: false,
                        title: '提示',
                        btnAlign:'r',
                        closeBtn: 3,
                        btn: ['已签约，不再提醒', '未签约'],
                        success: function () {
                              $(".layui-layer-content").css('text-align', 'left');
                          }
                    }, function() {
                        $('#mobile_mark').val(2);
                        layer.closeAll();
                    }, function(index) {
                        $(obj).attr('checked', false);
                        layer.closeAll(index);
                    });
                }
            }

            // 勾选移动端则执行
            // if (2 == $(obj).val()) $('#UseTutorial').show();
        } else {
            // 取消勾选移动端则执行
            // if (2 == $(obj).val()) $('#UseTutorial').hide();
        }
    }
</script>
{include file="public/footer" /}